import json, requests, os
from flask import Flask, request

app = Flask(__name__)

file_path = './NLP识别部分合同'

def send_req(f,cont_index):

    method="POST"
    # headers={'Content-Type': 'application/json'}
    url = "http://localhost:5000/upload_contract"
    data = {
            "contract_id" : str(cont_index),
        }
    res = requests.request(method, url=url, data=data,files={"file":open(f,'rb')})
    return res

@app.route('/abc', methods=["POST"])
def get_ht():
    print(request.data)
    data = json.loads(request.data)
    print(data["data"])
    contract_id = data["data"].get('contract_id','')
    print(contract_id)
    cont_index = int(contract_id)+1
    f_list = []
    for dirname,subdirs,files in os.walk(file_path):
        f_list = files
    res = send_req(dirname+'/'+files[int(contract_id)],cont_index)
    print(res.text)
    return "200"



if __name__ == '__main__':
    app.run(debug=True, port=5001, host='0.0.0.0')